package com.teatrace.action.process;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.interceptor.ServletRequestAware;

import com.opensymphony.xwork2.ActionSupport;
import com.teatrace.model.process.DryingStatus;
import com.teatrace.model.process.KilloutStatus;
import com.teatrace.model.process.RollingStatus;
import com.teatrace.model.produce.MaterialPackage;
import com.teatrace.service.process.ProcessService;
import com.teatrace.service.process.impl.ProcessServiceImpl;

public class GreenTeaProcess extends ActionSupport implements ServletRequestAware{
		
	private HttpServletRequest servletRequest;	
	private KilloutStatus ks;
	private RollingStatus rs;
	private DryingStatus ds;
	private String materialpackageid;
			
	
    //增加杀青状态
	public String AddKilloutStatus(){
		System.out.println("动作：增加杀青状态");
		materialpackageid = servletRequest.getParameter("materialpackageid");
        System.out.println(materialpackageid);
        ProcessService ps = new ProcessServiceImpl();      
        return ps.AddKilloutStatus(ks,Integer.parseInt(materialpackageid));  
        //return SUCCESS;       
	}
	
	//增加揉捻状态
	public String AddRollingStatus(){	
		System.out.println("动作：增加揉捻状态");
		//System.out.println(rs.getShape());
		//System.out.println(rs.getMaterialpackage().getId());
		ProcessService ps = new ProcessServiceImpl();
		return ps.AddRollingStatus(rs);
	}
	
	//增加干燥状态
	public String AddDryingStatus(){
		System.out.println("动作：增加干燥状态");
		ProcessService ps = new ProcessServiceImpl();
		return ps.AddDryingStatus(ds);
	}
	
	//从数据库取出各种加工阶段（如已经杀青、已经揉捻）的原料包，放进request中，传递给页面GrennTeaProcessInfos.jsp
	public String Show(){
		System.out.println("动作：show");
		ProcessService ps  =  new ProcessServiceImpl(); 
		List<KilloutStatus> kss = ps.GetKilloutedPackages();
		servletRequest.setAttribute("killoutedPackages",kss);
		List<RollingStatus> rss = ps.GetRolledPackages();
		servletRequest.setAttribute("rolledPackages", rss);
		List<DryingStatus> dss = ps.GetDriedPackages();
		servletRequest.setAttribute("driedpackages", dss);
		List<MaterialPackage> mps = ps.GetMaterialPackagesToBeProcessed();
		servletRequest.setAttribute("MaterialPackagesToBeProcessed", mps);
		return SUCCESS;
	}

	public RollingStatus getRs() {
		return rs;
	}

	public void setRs(RollingStatus rs) {
		this.rs = rs;
	}

	public DryingStatus getDs() {
		return ds;
	}

	public void setDs(DryingStatus ds) {
		this.ds = ds;
	}

	public String getMaterialpackageid() {
		return materialpackageid;
	}

	public void setMaterialpackageid(String materialpackageid) {
		this.materialpackageid = materialpackageid;
	}

	public HttpServletRequest getServletRequest() {
		return servletRequest;
	}

	public KilloutStatus getKs() {
		return ks;
	}

	public void setKs(KilloutStatus ks) {
		this.ks = ks;
	}

	public void setServletRequest(HttpServletRequest servletRequest) {
	  this.servletRequest = servletRequest;		
	}
}
